package com.lhj.security.support;

import com.lhj.security.dao.UserDao;
import com.lhj.security.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


/**
 * @author linghaijin
 * @date 2020-04-10 16:36
 */
@Slf4j
@Service("myUserDetailService")
public class MyUserDetailService implements UserDetailsService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
        SysUser sysUser = userDao.getUserByUsername(name);
        if (null == sysUser) {
            throw new UsernameNotFoundException(name);
        }
        log.info("用户权限："+sysUser.getAuthorities());
        return sysUser;
    }
}
